package com.chh.exam.security.service;

import com.chh.exam.security.entity.SecurityUser;
import com.chh.exam.user.entity.User;
import com.chh.exam.user.mapper.UserMapper;
import jakarta.annotation.Resource;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;
/**
 * @author: chh
 * @Desc:
 * @create: 2025-01-06 21:47
 **/
@Service
public class UserDetailsServiceImpl implements UserDetailsService {
    @Resource
    private UserMapper userMapper;

    @Override
    public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {

        User user = userMapper.getUserByName(username);
        if(user == null){
            throw new UsernameNotFoundException("用户名不存在");
        }


        return new SecurityUser(user);
    }
}
